package com.neusoft.hifly.push.email.pojo;

import java.io.Serializable;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

/**
 * Title: 核心类库
 * <p>
 * Description: 发邮件实体
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
public class MailSenderInfo implements Serializable {

	/**
	 * 字符串中的回车符 \r\n
	 */
	public static final String TAG_R_N = "\r\n";
	/**
	 * 邮件的回车符 br
	 */
	public static final String EMAIL_ENTER_SIGN = "</br>";

	private static final long serialVersionUID = -895195953542356206L;
	// 发送邮件的服务器的IP
	private String host;
	// 发送邮件的服务器的端口
	private int port = 25;
	// 登陆邮件发送服务器的密码
	private String userName;
	// 登陆邮件发送服务器的用户名
	private String password;
	// 邮件发送者的地址      (多个地址以(英文)分号分割)
	private String fromAddress;
	// 邮件接收者的地址    (多个地址以(英文)分号分割)
	private String toAddress;
	// 邮件抄送者的地址     (多个地址以(英文)分号分割)
	private String ccAddress;
	// 是否需要身份验证
	private boolean validate = false;
	// 邮件主题
	private String subject;
	// 邮件的文本内容
	private String content;
	// 邮件附件的文件名   ：key是文件真实名称，value为文件路径
	private Map<String, String> attachs;
	// 是否开启Debug调试
	private boolean isDebug = false;

	/**
	 * 获得邮件会话属性
	 */
	public Properties getProperties() {
		final Properties p = new Properties();
		p.put("mail.smtp.host", this.host);
		p.put("mail.smtp.port", this.port);
		p.put("mail.smtp.auth", validate ? "true" : "false");
		return p;
	}

	/**
	 * 防止有人用错了回车符，这里替换下
	 *
	 * @return 邮件内容
	 */
	public String getContent() {
		if (StringUtils.isNotEmpty(content)) {
			content = content.replaceAll(MailSenderInfo.TAG_R_N, MailSenderInfo.EMAIL_ENTER_SIGN);
		}
		return content;
	}

	public String getHost() {
		return host;
	}

	public void setHost(final String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(final int port) {
		this.port = port;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(final String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	public String getFromAddress() {
		return fromAddress;
	}

	public void setFromAddress(final String fromAddress) {
		this.fromAddress = fromAddress;
	}

	public String getToAddress() {
		return toAddress;
	}

	public void setToAddress(final String toAddress) {
		this.toAddress = toAddress;
	}

	public String getCcAddress() {
		return ccAddress;
	}

	public void setCcAddress(final String ccAddress) {
		this.ccAddress = ccAddress;
	}

	public boolean isValidate() {
		return validate;
	}

	public void setValidate(final boolean validate) {
		this.validate = validate;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(final String subject) {
		this.subject = subject;
	}

	public Map<String, String> getAttachs() {
		return attachs;
	}

	public void setAttachs(final Map<String, String> attachs) {
		this.attachs = attachs;
	}

	public boolean isDebug() {
		return isDebug;
	}

	public void setDebug(final boolean isDebug) {
		this.isDebug = isDebug;
	}

	public void setContent(final String content) {
		this.content = content;
	}

}
